package com.hz.friends.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hz.friends.utils.BitmapUtils;

public class GroupInfoActivity extends BaseActivity implements  OnClickListener{
	private LinearLayout layoutheard1;
	private LinearLayout layoutheard2;
	private LinearLayout layout_groupmembers;
	private Button btn_invitefrid;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_groupinfo);
		initViews();
		addTopImages();
	}

	@Override
	protected void init() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void initViews() {
		ImageButton imbtn_bar_left = (ImageButton) findViewById(R.id.imbtn_bar_left);
		ImageButton imbtn_bar_right = (ImageButton) findViewById(R.id.imbtn_bar_right);
		TextView imbtn_bar_title = (TextView) findViewById(R.id.imbtn_bar_title);
		imbtn_bar_right.setVisibility(View.INVISIBLE);
		imbtn_bar_title.setText("Edit data");
		imbtn_bar_left.setImageResource(R.drawable.ic_leftback_arrow);
		imbtn_bar_left.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
               finish();				
			}
		});
		
		
		layoutheard1 = (LinearLayout)findViewById(R.id.layoutheard1); //图片展示第一排
		layoutheard2 = (LinearLayout)findViewById(R.id.layoutheard2);//图片展示第二排
		layout_groupmembers = (LinearLayout)findViewById(R.id.layout_groupmembers);//图片展示第二排
		layout_groupmembers.setOnClickListener(this);

		btn_invitefrid = (Button)findViewById(R.id.btn_invitefrid);
		btn_invitefrid.setOnClickListener(this);
	}
	
	private void addTopImages(){
		DisplayMetrics metric = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metric);
		int mScreenWidth = metric.widthPixels;
		int offset = (int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 11*2+6*3, getResources()
						.getDisplayMetrics());
		int rightmargin = (int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 6, getResources()
						.getDisplayMetrics());
		int radius = (int) TypedValue.applyDimension(
				TypedValue.COMPLEX_UNIT_DIP, 6, getResources()
				.getDisplayMetrics());
		int width = (mScreenWidth - offset)/4;
		Bitmap bitmap = BitmapUtils.createRoundConerImage(BitmapFactory.decodeResource(getResources(), R.drawable.test1),width,radius);
		for (int i = 0; i < 2; i++) {
			ImageView mimageview = new ImageView(this);
//			mimageview.setImageResource(R.drawable.test_pic5);
			mimageview.setImageBitmap(bitmap);
			mimageview.setScaleType(ScaleType.FIT_XY);
			LinearLayout.LayoutParams lap = new LinearLayout.LayoutParams(width, width);
			if(i != 3)
			lap.rightMargin = rightmargin;
			mimageview.setLayoutParams(lap);
			layoutheard1.addView(mimageview);
			mimageview.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(GroupInfoActivity.this, BigImageActivity.class);
					intent.putExtra("res",  R.drawable.test1);
					startActivity(intent);
				}
			});
			
		}
		
//		for (int i = 0; i < 2; i++) {
//			ImageView mimageview = new ImageView(this);
//			mimageview.setImageBitmap(bitmap);
//			mimageview.setScaleType(ScaleType.FIT_CENTER);
//			LinearLayout.LayoutParams lap = new LinearLayout.LayoutParams(width, width);
//			if(i != 3)
//			lap.rightMargin = rightmargin;
//			mimageview.setLayoutParams(lap);
//			layoutheard2.addView(mimageview);
//		}
	}


	@Override
	protected void setViews() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void initEvents() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.layout_groupmembers:
			startActivity(GroupMembersActivity.class);
			break;
		case R.id.btn_invitefrid:
			startActivity(InviteFriendsActivity.class);
			break;
		default:
			break;
		}
	}
}
